package com.soc.secondtest.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author NieYinjun
 * @date 2019/1/25 11:45
 * @tag
 */
@RestController

public class IndexController {

    @RequestMapping("/")
    @ResponseBody
    public Object index(){
        return "this is index page";
    }

    @RequestMapping("/query")
    @ResponseBody
    public Object tdengineTest(String sqls){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();

        headers.setBasicAuth("root","taosdata");

        HttpEntity<String> request = new HttpEntity<>(sqls,headers);
        //url中不写库名，那么sql中要带库名.表名
        return restTemplate.postForObject("http://172.16.58.110:6041/rest/sql/demo", request, Object.class);
    }

}
